package gamble.notice.command;

import gamble.notice.dao.BoardDaoImp;
import gamble.notice.vo.BoardVO;
import gamble.notice.vo.PageVO;

import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;


@Controller
public class ViewController {
	BoardVO vo;
	PageVO pv;
	int currentPage;
	int num;
	String writer;
	private BoardDaoImp dao;	
	
	public void setDao(BoardDaoImp dao) {
		this.dao = dao;
	}


	@RequestMapping("/view.htm")
	public ModelAndView viewMethod(HttpServletRequest req)  {
		    num=Integer.parseInt(req.getParameter("num"));
		   writer=req.getParameter("writer");
		    System.out.println("num:"+num);
		    System.out.println("writer:"+writer);
		    currentPage=Integer.parseInt(req.getParameter("currentPage"));
		
		    dao.getInc(num);
			vo=dao.getView(num);
			
			pv=new PageVO();
			pv.setCurrentPage(currentPage);			
			
			if(!vo.getUpload2().isEmpty()){
		     String str=vo.getUpload2();		    
			 vo.setUpload2(str.substring(str.indexOf("_")+1));
			}			
			
			ModelAndView mv=new ModelAndView();
			mv.addObject("vo",vo);
			
			
			mv.addObject("pv",pv);
			mv.setViewName("view");		
		return mv;
	}
}
